﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace QuanLyThuChi
{
    class public_function
    {
        connect cn = new connect();
        public bool kiemTraTonTai(string dk,string proc, string para)
        {           
            OleDbCommand cmd = new OleDbCommand(proc,cn.ketnoi());
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new OleDbParameter(para, OleDbType.VarChar)).Value = dk;
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            if (dt.Rows.Count<=0)
            {
                return false;
            }
            return true;         
            cn.ketnoi().Dispose();
        }
        public DataTable getData(string sql)
        {
            OleDbCommand cmd = new OleDbCommand(sql, cn.ketnoi());
            cmd.CommandType = CommandType.StoredProcedure;
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }
        public double thanhtien(double soluong, double dongia)
        {
            if ( soluong <=0)
            {
                return 0;
            }
            else if (dongia <=0)
            {
                return 0;
            }
            return soluong * dongia;
        }
    }
}
